package com.huika.dealontop.views;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.huika.dealontop.R;


public class CustomSearchBar {

    private PopupWindow popupWindow;

    // begin---底部弹出宽，类似苹果的//////////////////////////////////////////
    public CustomSearchBar(Context context, int layoutId) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(layoutId, null);
        final int cFullFillWidth = 10000;
        layout.setMinimumWidth(cFullFillWidth);


        // set a large value put it in bottom
        //final Dialog dlg = new Dialog(context, R.style.MMTheme_DataSheet);
//		Window w = dlg.getWindow();
//		WindowManager.LayoutParams lp = w.getAttributes();
//		lp.x = 0;
//		final int cMakeBottom = -1000;


        popupWindow = new PopupWindow(layout, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        popupWindow.setFocusable(true);
        popupWindow.setAnimationStyle(R.style.DataSheetAnimation);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setOutsideTouchable(true);
//		lp.y = cMakeBottom;
        popupWindow.setContentView(layout);
//
//		lp.gravity = Gravity.BOTTOM;// 改变显示位置
//		dlg.onWindowAttributesChanged(lp);
//		dlg.setCanceledOnTouchOutside(false);

//		dlg.setContentView(layout);


    }

    public void Animation_out(View view) {
        //popupWindow.setAnimationStyle(R.anim.search_push_out);
        //popupWindow.showAtLocation(view,Gravity.NO_GRAVITY,0,popupWindow.getHeight());

        popupWindow.showAsDropDown(view, 0, -view.getMeasuredHeight());
        ;
    }

    public void Animation_in() {
        popupWindow.setAnimationStyle(R.anim.search_push_out);
        popupWindow.showAsDropDown(null);
    }


}
